package com.ikangtai.shecare.stickycalendar.recordButton;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;

import com.ikangtai.shecare.R;
import com.ikangtai.shecare.common.RecordFragmentCommonList;
import com.ikangtai.shecare.common.baseView.recordButtonView.RecordSelectButton;
import com.ikangtai.shecare.main.RecordFragment;

/**
 * Created by Administrator on 2016/1/28.
 */
public class MenstruationButton extends RecordSelectButton {

    private Context context;
    public static final int RECORD_MUCUS_SELECT_WHITE_BACKGROUND_COLOR = 0;
    public static final int RECORD_MUCUS_SELECT_PURPLE_BACKGROUND_COLOR = 1;
    public static final String RecordSelectMucusButtonType = "MUCUS";

    public MenstruationButton(Context context) {
        super(context);
        this.context = context;
        setType(RecordSelectMucusButtonType);
    }

    public MenstruationButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        this.backgroundColor = RECORD_MUCUS_SELECT_WHITE_BACKGROUND_COLOR;
    }

    @Override
    public void setColor(int backGroundColor) {
        super.setColor(backGroundColor);
        if (backGroundColor == RECORD_MUCUS_SELECT_WHITE_BACKGROUND_COLOR) {
            this.setBackground(getResources().getDrawable(R.drawable.ca_record_mucus_button_default));
            this.setTextColor(getResources().getColor(R.color.mucus_color));
        } else if (backGroundColor == RECORD_MUCUS_SELECT_PURPLE_BACKGROUND_COLOR) {
            this.setBackground(getResources().getDrawable(R.drawable.ca_record_mucus_button_pressed));
            this.setTextColor(Color.WHITE);
        }
    }

    @Override
    public void clickAction(View view) {
        if (null != view) {

            if (backgroundColor == RECORD_MUCUS_SELECT_WHITE_BACKGROUND_COLOR) {
                this.setBackground(getResources().getDrawable(R.drawable.ca_record_mucus_button_pressed));
                this.setTextColor(Color.WHITE);
                backgroundColor = RECORD_MUCUS_SELECT_PURPLE_BACKGROUND_COLOR;
                //调整关联判断按钮状态

                for (int i = 0; i < RecordFragmentCommonList.mucusStatusButton.length; i++) {
                    if (this.getId() == RecordFragmentCommonList.mucusStatusButton[i]) {
                        RecordFragment.mucusStatus = i + 1;
                        for (int j = 0; j < RecordFragmentCommonList.mucusStatusButton.length; j++) {
                            if (RecordFragmentCommonList.mucusStatusButton[i] != RecordFragmentCommonList.mucusStatusButton[j]) {
                                MenstruationButton button = (MenstruationButton) view.findViewById(RecordFragmentCommonList.mucusStatusButton[j]);
                                button.setColor(RECORD_MUCUS_SELECT_WHITE_BACKGROUND_COLOR);
                                button.setTextColor(getResources().getColor(R.color.mucus_color));
                            }
                        }
                    }
                }

                for (int i = 0; i < RecordFragmentCommonList.mucusFlowButton.length; i++) {
                    if (this.getId() == RecordFragmentCommonList.mucusFlowButton[i]) {
                        RecordFragment.mucusFlow = i + 1;
                        for (int j = 0; j < RecordFragmentCommonList.mucusFlowButton.length; j++) {
                            if (RecordFragmentCommonList.mucusFlowButton[i] != RecordFragmentCommonList.mucusFlowButton[j]) {
                                MenstruationButton button = (MenstruationButton) view.findViewById(RecordFragmentCommonList.mucusFlowButton[j]);
                                button.setColor(RECORD_MUCUS_SELECT_WHITE_BACKGROUND_COLOR);
                                button.setTextColor(getResources().getColor(R.color.mucus_color));
                            }
                        }
                    }
                }

                for (int i = 0; i < RecordFragmentCommonList.mucusColorButton.length; i++) {
                    if (this.getId() == RecordFragmentCommonList.mucusColorButton[i]) {
                        RecordFragment.mucusColor = i + 1;
                        for (int j = 0; j < RecordFragmentCommonList.mucusColorButton.length; j++) {
                            if (RecordFragmentCommonList.mucusColorButton[i] != RecordFragmentCommonList.mucusColorButton[j]) {
                                MenstruationButton button = (MenstruationButton) view.findViewById(RecordFragmentCommonList.mucusColorButton[j]);
                                button.setColor(RECORD_MUCUS_SELECT_WHITE_BACKGROUND_COLOR);
                                button.setTextColor(getResources().getColor(R.color.mucus_color));
                            }
                        }
                    }
                }
            } else {
                this.setBackground(getResources().getDrawable(R.drawable.ca_record_mucus_button_default));
                this.setTextColor(getResources().getColor(R.color.mucus_color));
                this.backgroundColor = RECORD_MUCUS_SELECT_WHITE_BACKGROUND_COLOR;

                for (int i = 0; i < RecordFragmentCommonList.mucusStatusButton.length; i++) {
                    if (this.getId() == RecordFragmentCommonList.mucusStatusButton[i]) {
                        RecordFragment.mucusStatus = 0;
                    }
                }

                for (int i = 0; i < RecordFragmentCommonList.mucusFlowButton.length; i++) {
                    if (this.getId() == RecordFragmentCommonList.mucusFlowButton[i]) {
                        RecordFragment.mucusFlow = 0;

                    }
                }

                for (int i = 0; i < RecordFragmentCommonList.mucusColorButton.length; i++) {
                    if (this.getId() == RecordFragmentCommonList.mucusColorButton[i]) {
                        RecordFragment.mucusColor = 0;
                    }
                }

            }
        }
    }
}
